﻿using AutoMapper;
using MediatR;
using Traceable.App.Application.Command.Aquaculture;
using Traceable.App.DTOS;
using Traceable.Domian;
using Traceable.ErrorCode;
using Traceable.Infastructure;

namespace Traceable.App.Application.Handler.Aquaculture
{
    public class GetImmunityHandler : IRequestHandler<GetImmunityCommand, ApiResult<List<ImmunityDto>>>
    {
        private readonly IBaseRepository<Immunity_Table> _immunityRepo;
        private readonly IMapper _mapper;

        public GetImmunityHandler(IBaseRepository<Immunity_Table> immunityRepo, IMapper mapper)
        {
            _immunityRepo = immunityRepo;
            _mapper = mapper;
        }
        /// <summary>
        /// 获取免疫信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<List<ImmunityDto>>> Handle(GetImmunityCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ImmunityDto>> result = new ApiResult<List<ImmunityDto>>();

            var immunity = _immunityRepo.GetAll().Where(p => p.Batch_Id == request.Batch_Id && !p.IsDelete);

            result.Code = StatusEnum.OK;
            result.Data=_mapper.Map<List<ImmunityDto>>(immunity);
            result.Message = "获取成功";
            return Task.FromResult(result);
        }
    }
}
